/**
 * Created by szc on 2017/1/10.
 */
class CrystalDisB extends egret.DisplayObjectContainer {
    private url: any;
    private crystalPanle: any;
    private context: any;
    private numPanle: any
    private numArr: any;
    public curNum: any;
    public curNumS: any;
    private curmax: any;
    private image_add: any;
    private image_plus: any;
    private bWidth: number = 100;
    private bHeight: number = 85;
    public constructor(url: any, crystalPanle: any, numArr: any, context: any) {
        super();
        this.url = url;
        this.crystalPanle = crystalPanle;
        this.numArr = numArr;
        this.curmax = numArr.length;
        this.context = context;
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
    }
    private onAddToStage(event: egret.Event) {

        var crystalPanle = this.crystalPanle;
        var _group = this;

        // var imagebg = new eui.Image();
        // imagebg.source = "lottery_frame_a_png";
        // imagebg.width = this.bHeight * 1.5;
        // imagebg.height = this.bHeight * 0.7;
        // _group.addChild(imagebg);

        // var image_add = this.image_add = new eui.Image();
        // image_add.source = "null_png";
        // image_add.width = this.bHeight * 0.35;
        // image_add.height = this.bHeight * 0.35;
        // image_add.touchEnabled = true;
        // image_add.y = this.bHeight * 0.3;
        // image_add.x = imagebg.width - image_add.width;
        // image_add.addEventListener(egret.TouchEvent.TOUCH_TAP, this.nextNum, this);
        // _group.addChild(image_add);

        // var image_plus = this.image_plus = new eui.Image();
        // image_plus.source = "null_png";
        // image_plus.width = this.bHeight * 0.35;
        // image_plus.height = this.bHeight * 0.35;
        // // image_plus.x =
        // image_plus.touchEnabled = true;
        // image_plus.y = this.bHeight * 0.3;
        // image_plus.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lastNum, this);
        // _group.addChild(image_plus);

        var image_bg = new eui.Image();
        image_bg.source = "no_kuang_png";
        image_bg.y = 5;
        image_bg.x = 0;
        image_bg.$setScaleX(0.6);
        image_bg.$setScaleY(0.6);
        _group.addChild(image_bg);


        var image_top = new eui.Image();
        image_top.source = this.url;
        image_top.y = -25;
        image_top.x = 40;
        image_top.$setScaleX(0.6);
        image_top.$setScaleY(0.6);
        _group.addChild(image_top);

        this.numPanle = new NumPanel2(15 * 0.8, 22.5 * 0.8, "w_");
        this.numPanle.x = 70;
        this.numPanle.y = 35;
        this.addChild(this.numPanle);
        this.setNum(0);
    }
    public setNum(signal: any): void {
        this.curNumS = signal;
        this.curNum = this.numArr[signal];
        this.numPanle.setNum(this.numArr[signal]);
        // this.numPanle.x = (this.bHeight * 1.5 - this.numPanle.width) / 2 + this.numPanle.width;
        this.reState();
    }

    public nextNum(): void {
        if (this.curNumS > this.curmax - 2) {
            return;
        }
        this.setNum(this.curNumS + 1);
        this.context.ca_zhu();
        this.reState();
    }

    public lastNum(): void {
        if (this.curNumS < 1) {
            return;
        }

        this.setNum(this.curNumS - 1);
        this.context.ca_zhu();
        this.reState();
    }

    public getNum(): any {
        return this.curNum;
    }


    /**
      * 将这个控制面板设置为不可编辑
      */
    public setDisState(): void {
        // this.image_add.touchEnabled = false;
        // this.image_add.source = "rl_add_dis_png";

        // this.image_plus.touchEnabled = false;
        // this.image_plus.source = "rl_plus_dis_png";

    }

    /**
     * 设置成可编辑状态
     */
    public setEditabledState(): void {
        this.reState();
    }

    /**
     * 重新渲染状态
     */
    public reState(): void {
        // if (this.curNumS == 0) {
        //     // this.image_add.touchEnabled = true;
        //     // this.image_add.source = "rl_add_png";

        //     // this.image_plus.touchEnabled = false;
        //     // this.image_plus.source = "rl_plus_dis_png";

        //     return;
        // }

        // if (this.curNumS == this.curmax - 1) {
        //     this.image_add.touchEnabled = false;
        //     this.image_add.source = "rl_add_dis_png";

        //     this.image_plus.touchEnabled = true;
        //     this.image_plus.source = "rl_plus_png";
        //     return;
        // }

        // this.image_add.touchEnabled = true;
        // this.image_add.source = "rl_add_png";

        // this.image_plus.touchEnabled = true;
        // this.image_plus.source = "rl_plus_png";
    }

}